﻿using System.Modules.Constants;

namespace System.Modules.Utility.DTO.ULS.Monitoring
{
    class LogEntry
    {
        public enum FieldNames
        {
            Timestamp,
            Process,
            TID,
            Area,
            Category,
            EventID,
            Level,
            Message,
            Correlation
        }

        #region Properties
        public string Timestamp { get; set; }
        public string Process { get; set; }
        public string TID { get; set; }
        public string Area { get; set; }
        public string Category { get; set; }
        public string EventID { get; set; }
        public string Level { get; set; }
        public string Message { get; set; }
        public string Correlation { get; set; }
        #endregion

        #region Methods
        public static LogEntry Parse(string line)
        {
            var fields = line.Split(new[] { EscapeCharacter.HORIZONTAL_TAB }, StringSplitOptions.RemoveEmptyEntries);
            if (fields.Length > 8)
            {
                var entry = new LogEntry();
                entry.Timestamp = fields[0].Trim();
                entry.Process = fields[1].Trim();
                entry.TID = fields[2].Trim();
                entry.Area = fields[3].Trim();
                entry.Category = fields[4].Trim();
                entry.EventID = fields[5].Trim();
                entry.Level = fields[6].Trim();
                entry.Message = fields[7].Trim();
                entry.Correlation = fields[8].Trim();
                return entry;
            }
            return null;
        }
        #endregion
    }
}
